package com.sigmatrix.h5.service.log;

import java.util.Date;
import java.util.concurrent.atomic.AtomicInteger;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;

import com.sigmatrix.h5.message.bigdata.BigDataInStorage;
import com.sigmatrix.h5.utils.JsonUtils;

public class BigDataLogger {
	
	private static Logger logger = LoggerFactory.getLogger(BigDataLogger.class);
	
	private static AtomicInteger logSerial = new AtomicInteger(0);
	
	/**
	 * 
	 * @param logType
	 *            日志类型
	 * @param msg
	 *            业务日志
	 */
	public static synchronized void loggerInfo(String logType, Object obj) {
		MDC.put("log_type", logType);
		MDC.put("log_user", "bigdata");
		MDC.put("serial", "" + getSerial());
		logger.info(JsonUtils.objectToJson(obj));
		MDC.clear();
	}

	private static int getSerial() {
		int serial = logSerial.incrementAndGet();
		if (serial == Integer.MAX_VALUE) {
			logSerial.set(0);
		}
		return serial;
	}
	public static void main(String args []) {
		BigDataInStorage ins=  new BigDataInStorage();
		ins.setActualNumber(2);
//		ins.setApp("ddd");
		ins.setCity(623);
		
		loggerInfo(ins.getLogType(),ins);
	} 
}
